import moment from "moment";
import { Space, Tag, Typography } from "antd";
import {
  CheckCircleOutlined,
  MinusCircleOutlined,
  SyncOutlined,
} from "@ant-design/icons";
import { getItem } from "@/utils/localstorage";
import Https from "@/utils/Https";
export const namespace = "coursePersonal";
const dayList = ["日", "一", "二", "三", "四", "五", "六"];
const { Text } = Typography;
const coachRequest = async () => {
  let params = {
    venueId: getItem("venueInfo").id,
  };
  let res: any = await Https.get("/employee/manage/listCoach", params, true);
  let objList = [];
  if (res.code == 200 && res.data) {
    if (res.data.length > 0) {
      res.data.map((e) => objList.push({ label: e.nickName, value: e.userId }));
    }
  }
  return objList;
};
export const calcColumns = (params) => {
  const { operate } = params;

  const columns = [
    {
      title: "会员信息",
      dataIndex: "wechatUserInfo",
      hideInSearch: true,
      render: (_, record) => {
        return (
          <Space direction="vertical" size="small">
            <Text>{record.wechatUserName}</Text>
            <Text type="secondary">{record.wechatUserPhone}</Text>
          </Space>
        );
      },
    },
    {
      title: "关键字",
      dataIndex: "searchValue",
      hidden: true,
      fieldProps: {
        placeholder: "请输入昵称/手机号",
      },
    },
    {
      title: "授课老师",
      dataIndex: "courseCoachName",
      hidden: "true",
      request: coachRequest,
      valueType: "select",
      search: {
        transform: (e) => {
          const courseCoachId = e;
          return {
            courseCoachId,
          };
        },
      },
    },
    {
      title: "上课时间",
      dataIndex: "classStartTime",
      valueType: "dateRange",
      //width: 250,
      render: (_, record) => {
        return (
          <Space direction="vertical" size="small">
            <Text>
              {moment(record.bookStartTime).format("YYYY-MM-DD") +
                " (" +
                dayList[new Date(record.bookStartTime).getDay()] +
                ") "}
            </Text>
            <Tag
              icon={
                record.status == 2 ? (
                  <SyncOutlined spin />
                ) : record.status == 3 ? (
                  <CheckCircleOutlined />
                ) : (
                  <MinusCircleOutlined />
                )
              }
              color={
                record.status == 2
                  ? "processing"
                  : record.status == 3
                  ? "success"
                  : "default"
              }
            >
              {moment(record.bookStartTime).format("HH:mm") +
                "～" +
                moment(record.bookEndTime).format("HH:mm")}
            </Tag>
          </Space>
        );
      },
      // render: (_, record) => {
      //   return (
      //     moment(record.bookStartTime).format("YYYY-MM-DD") +
      //     " (" +
      //     dayList[new Date(record.bookStartTime).getDay()] +
      //     ") " +
      //     moment(record.bookStartTime).format("HH:mm") +
      //     "~" +
      //     moment(record.bookEndTime).format("HH:mm")
      //   );
      // },
      search: {
        transform: (e) => {
          const [startTime, endTime] = e;
          return {
            startTime,
            endTime,
          };
        },
      },
    },
    {
      title: "课程名称",
      dataIndex: "courseName",
      ellipsis: true,
      hidden: "true",
    },
    {
      title: "课程信息",
      dataIndex: "courseNameInfo",
      hideInSearch: true,
      render: (_, record) => {
        return (
          <Space direction="vertical" size="small">
            <Text copyable>{record.courseName}</Text>
            <Text type="secondary">{record.courseCoachName}</Text>
          </Space>
        );
      },
    },
    {
      title: "预约状态",
      dataIndex: "status",
      valueEnum: {
        // 1排队中、2已预约、3已完成、4已取消
        1: { text: "排队中", status: "" },
        2: { text: "已预约", status: "processing" },
        3: { text: "已完成", status: "success" },
        4: { text: "已取消", status: "Error" },
      },
    },
    {
      title: "签到状态",
      dataIndex: "signinFlag",
      valueEnum: {
        // 0 未签到 1已签到
        0: { text: "未签到", status: "default" },
        1: { text: "已签到", status: "success" },
      },
    },
  ];

  columns.push(operate);
  return columns;
};
